<template>
	<view>
		<view class="points_top">
			<view class="points">
				<view class="potinsItem">
					<view class="points_title">
						积分
					</view>
					<view class="points_number">
						{{points}}
					</view>
				</view>
			</view>
		</view>
		<view class="points_content">
			<button class="points_rule" @click="goPointsRule">
				积分规则
			</button>
			<view class="points_list">
				<view class="list_title">积分明细</view>
				<u-empty mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" v-if="pointsRecords.length==0">
				</u-empty>
				<view class="points_item" v-for="item in pointsRecords" :key="item.id">
					<view class="item_left">
						<view class="item_content">{{item.content}}</view>
						<view class="item_create_time">{{item.createTime}}</view>
					</view>
					<view class="item_value">{{item.points > 0 ? '+' : ''}}{{item.points}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				points:0,
				pointsRecords:[]
			}
		},
		onLoad(){
			this.getUserPointsRecords();
			this.getUserPoints();
		},
		methods: {
			async getUserPointsRecords(){
				const res = await this.$myRequest({
					url:'user/pointsRecord/list'
				})
				if(res && res.code === 0){
					this.pointsRecords = res.data;
				}
				let points = 0;
				this.pointsRecords.forEach(item=>{
					points += item.points;
				})
				this.points = points;
			},
			async getUserPoints(){
				const res = await this.$myRequest({
					url:'user/pointsRecord/getUserPoints'
				})
				this.points = res.data
			},
			goPointsRule(){
				uni.navigateTo({
					url:'/pages/consultingInformation/consultingInformation?data=2'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8;
	}

	.points_top {
		height: 300rpx;
		padding: 40rpx 50rpx 0 50rpx;

		.points {
			border-radius: 20rpx 20rpx 0 0;
			width: 550rpx;
			height: 240rpx;
			background-color: #FFB300;
			color: white;
			padding: 50rpx 0 0 100rpx;

			.points_title {
				font-size: 30rpx;
			}

			.points_number {
				font-size: 50rpx;
			}
		}
	}

	.points_content {
		background-color: white;
		padding: 30rpx 30rpx 0 30rpx;

		.points_rule {
			border-radius: 30rpx;
			font-size: 30rpx;
			width: 250rpx;
			color: white;
			background-color: #FFB300;
		}
		
		.list_title{
			margin-bottom: 30rpx;
		}
		
		.points_list{
			
			.points_item{
				padding-bottom: 10rpx;
				margin-bottom: 10rpx;
				display: flex;
				border-bottom: #F8F8F8 solid 0.1rpx;
				
				.item_content{
					font-size: 30rpx;
					margin-right: 400rpx;
				}
				
				.item_create_time{
					color: #808080;
					font-size: 25rpx;	
				}
			}
		}
	}
</style>
